Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vite): Fix CSS replacement in Vite HMR #73

Merged
merged 2 commits into from
Apr 16, 2024
Merged

Conversation

brijeshb42
Copy link
Contributor

@brijeshb42 brijeshb42 commented Apr 16, 2024

Also remove dependency on @rollup/plugin-utils

Motivation

This PR fixes an issue related to Vite plugin originally opened on Pigment CSS repo.

Summary

This change avoids the usage of css content slug in the filename and keeps the css filename unique just by using the path of the original js/ts file and using wyw-in-js prefix before the extension.
Using slug had an issue where if you removed a css property from your css definition, it would get applied in a new style tag during dev mode. Thus also keeping the old css in place which would result in overall css being applied from both old and new css content.

The fix instead keeps using the same filename regardless of the content and just pings the FE to reload the latest CSS content which it replaces in the existing style tag instead of adding a new one.

I also removed the explicit dependency of @rollup/plugin-utils since vite already re-exports those.

Test plan

Tested locally using this repo for the bug reproduction and fix.

Copy link

changeset-bot bot commented Apr 16, 2024

🦋 Changeset detected

Latest commit: 2e4e227

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Also remove dependency on @rollup/plugin-utils
@Anber Anber merged commit ee9e680 into Anber:main Apr 16, 2024
4 checks passed
@brijeshb42 brijeshb42 deleted the vite-hmr branch April 17, 2024 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants